package tjut.db;

import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSourceFactory;

public class DBDataSource {

	private static DataSource dateSource;
	
	//禁止外部创建该类实例对象
	private DBDataSource(){
		
	}
	public static DataSource getDataSource(){
		if(dateSource==null){
			try {
				Properties prop=new Properties();
				prop.load(DBDataSource.class.getClassLoader().getResourceAsStream("db.properties"));
				dateSource =BasicDataSourceFactory.createDataSource(prop);
			} catch (Exception e) {
				System.out.println("生成数据库连接池错误："+e.getMessage());
			}
			
		}
		
		return dateSource;
		
	}
}
